const app = getApp()
var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    controllerPicture:"30rpx"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.setData({
      id:id
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.returnOrderDetails();
  },
  //显示更多控制
  controllerPicture:function(){
    var text = this.data.controllerPicture;
    if (text =="30rpx"){
      text ="auto"
    }else{
      text = "30rpx"
    }
    this.setData({
      controllerPicture:text
    })
  },
  returnOrderDetails: function () {
    var that = this;
    var id = this.data.id;
    api.POST({
      params: { "id": id},
      url: app.globalData.base_url + 'aftersale/getInfo',
      success: function (res) {
        if (util.isEmpty(res.data.code)) {
          var productDetails = res.data.data;
          var total = (productDetails.number * productDetails.price).toFixed(2);
          that.setData({
            productDetails: productDetails,
            total: total,
          })
        }
      }
    })
  },
  logisticsNumber:function(e){
    var numbers = e.detail.value;
    this.setData({
      logisticsNumber: numbers
    })
  },
  logisticsCompany: function (e) {
    var company = e.detail.value;
    this.setData({
      logisticsCompany: company
    })
  },
  logisticsPrice: function (e) {
    var price = e.detail.value;
    this.setData({
      logisticsPrice: price
    })
  },
  submit:function(){
    var params = new Object()
    var that = this;
    var id = this.data.id;
    var fid = this.data.logisticsNumber;
    var express_name = this.data.logisticsCompany;
    var carriage = this.data.logisticsPrice;
    params.id = id;
    if (!fid){
      util.showError("请输入物流单号");
      
      return;
    }else{
      params.fid = fid;
    }
    if (!express_name) {
      
      util.showError("请输入物流公司");
      return;
    } else {
      params.express_name = express_name;
    }
    if (!carriage) {
      
      util.showError("请输入快递金额");
      return;
    } else {
      params.carriage = carriage;
    }


    api.POST({
      params: params,
      url: app.globalData.base_url + 'aftersale/fidSave',
      success: function (res) {
        if (util.isEmpty(res.data.code)) {
          wx.redirectTo({
            url: '../refundSuccessful/refundSuccessful?id=' + id
          })
        } else {
          util.showStatus(res.data.message)
        }
      },
      fail: function (fail) {
        util.showError("登录失败，请检查网络");
      }
    })
  }
})